/**
 * Created with IntelliJ IDEA.
 * Description:x的平方根
 * User: bjc
 * Date: 2025-11-16
 * Time: 15:53
 */
public class Test04_mySqrt {
    public int mySqrt(int x) {
        long left = 0, right = x;
        while (left <= right) {
            long mid = left + (right - left) / 2;
            if (mid * mid < x)
                left = mid + 1;
            else if (mid * mid > x)
                right = mid - 1;
            else
                return (int) mid;
        }
        return (int) right;
    }
}
